<?php

namespace plugin\wechat;

use plugin\wechat\app\service\Crontab as CrontabService;

class Install
{
    /**
     * 安装
     *
     * @param $version
     * @return void
     * @throws \think\db\exception\DbException
     */
    public static function install($version = '')
    {
        self::initCrontab();
    }

    /**
     * 卸载
     *
     * @param $version
     * @return void
     * @throws \think\db\exception\DbException
     */
    public static function uninstall($version = '')
    {
        self::stopCrontab();
    }

    /**
     * 更新
     *
     * @param $from_version
     * @param $to_version
     * @param $context
     * @return void
     * @throws \think\db\exception\DbException
     */
    public static function update($from_version, $to_version, $context = null)
    {
        self::initCrontab();
    }

    /**
     * @throws \think\db\exception\DbException
     * Author: fudaoji<fdj@kuryun.cn>
     */
    private static function initCrontab(){
        CrontabService::botTaskStart();
    }

    /**
     * @throws \think\db\exception\DbException
     * Author: fudaoji<fdj@kuryun.cn>
     */
    private static function stopCrontab(){
        CrontabService::botTaskStop();
    }
}